<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>有奖答题平台</title>
    <!-- ICON -->
    <link href="/frame/images/meatball.ico" type="image/ico" rel="shortcut icon">
    <!-- CSS -->
    <link rel="stylesheet" href="/lib/layuiadmin/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/lib/layuiadmin/css/admin.css" media="all">
</head>
<body layadmin-themealias="default">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15="">
                    <div class="layui-form" lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">当前密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="oldPsd" lay-verify="required" lay-vertype="tips" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="newPsd" lay-verify="pass" lay-vertype="tips" autocomplete="off" id="LAY_password" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="reNewPsd" lay-verify="repass" lay-vertype="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="setmypass">确认修改</button>
                                <input class="layui-hide" name="id" th:value="${session.sysUser.id}">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- JavaScript -->
<script type="text/javascript" src="/lib/layuiadmin/layui/layui.js"></script>
<!-- javascirpt -->
<script type="text/javascript" th:inline="none">
layui.config({
    base: '/lib/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index'], function() {
    var form = layui.form,
        $ = layui.$;

    form.verify({
        pass:[/^[\S]{6,12}$/,"密码必须6到12位，且不能出现空格"],
        // 验证二次输入是否正确
        repass: function(value) {
            if(value!==$("#LAY_password").val()){
                return"两次密码输入不一致"
            }
        }
    }).on('submit(setmypass)', function(data) {
        console.log(data.field);
        $.ajax({
            url: '/system/user/changepsd',
            type: 'PUT',
            async: true,
            data: data.field,
            success: function(res) {
                if(res.code == 10000) {
                    layer.msg(res.message, {icon: 1});
                    setTimeout(function () {
                        top.location.href = '/logout';
                    }, 3000)
                } else {
                    layer.msg(res.message, {icon: 5});
                }
            }
        })
    })
});
</script>
</body>
</html>